package utils;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class DBManagerTest {
    DBManager manager;
    
    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testGetInstance() {
	manager = DBManager.getInstance();
	assertNotNull(manager);
    }

    @Test
    public void testGetConnection() {
	manager = DBManager.getInstance();
	Connection connection = manager.getConnection();
	assertNotNull(connection);
	
    }

    @Test
    public void testExecuteQuery() {
	
	manager = DBManager.getInstance();
	ResultSet rs = manager.executeQuery("select * from user");
	
	assertNotNull(rs);
	int i= 0;
	try {
	    
	    while (rs.next()) {
	        System.out.println(rs.getString(3));
	        i++;
	    }
	} catch (SQLException e) {
	    e.printStackTrace();
	}
	
	assertEquals(i, 1);
    }

}
